//
//  WMEClubNewsHeadView.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/2/27.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEClubNewsHeadView.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "PrefixHeader.pch"
#pragma mark - 具体什么俱乐部的头部视图
@interface WMEClubNewsHeadView ()
@property (nonatomic, retain)UIImageView *backImg;/**<背景图片*/
@property (nonatomic, retain)UILabel *imgBackLabel;/**<俱乐部背景图片*/
@property (nonatomic, retain)UIImageView *clubImg;/**<俱乐部名字*/
@property (nonatomic, retain)UILabel *clubName;/**<俱乐部名*/
@property (nonatomic, retain)UILabel *clubContent;/**<俱乐部内容*/
@end

@implementation WMEClubNewsHeadView

-(void)dealloc
{
    [_NewsDic release];
    [_backImg release];
    [_imgBackLabel release];
    [_clubImg release];
    [_clubName release];
    [_clubContent release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //背景图片
        self.backImg = [[UIImageView alloc] init];
        _backImg.contentMode = UIViewContentModeScaleAspectFill;
        _backImg.clipsToBounds = YES;
        [self addSubview:_backImg];
        [_backImg release];
        
        //俱乐部背景图片
        self.imgBackLabel = [[UILabel alloc] init];
        _imgBackLabel.backgroundColor = [UIColor whiteColor];
        [self addSubview:_imgBackLabel];
        [_imgBackLabel release];
        
        //俱乐部图片
        self.clubImg = [[UIImageView alloc] init];
//        _clubImg.backgroundColor = [UIColor yellowColor];
        [self addSubview:_clubImg];
        [_clubImg release];
        
        //俱乐部名字
        self.clubName = [[UILabel alloc] init];
//        _clubName.backgroundColor = [UIColor orangeColor];
        _clubName.textColor = [UIColor whiteColor];
        _clubName.font = [UIFont boldSystemFontOfSize:15];
        [self addSubview:_clubName];
        [_clubName release];
        
        //俱乐部的介绍
        self.clubContent = [[UILabel alloc] init];
//        _clubContent.backgroundColor = [UIColor redColor];
        _clubContent.textColor = [UIColor whiteColor];
        _clubContent.font = [UIFont systemFontOfSize:13];
        _clubContent.numberOfLines = 0;
        [self addSubview:_clubContent];
        [_clubContent release];
    }
    return self;
}
- (void)setNewsDic:(NSDictionary *)NewsDic
{
    if (_NewsDic != NewsDic) {
        [_NewsDic release];
        _NewsDic = [NewsDic retain];
        [_backImg sd_setImageWithURL:[NSURL URLWithString:_NewsDic[@"photo"][@"path"]]];
        
        [_clubImg sd_setImageWithURL:[NSURL URLWithString:_NewsDic[@"photo"][@"path"]]];
        
        _clubName.text = _NewsDic[@"name"];
        
        _clubContent.text = _NewsDic[@"desc"];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
//    __block __typeof(&*self)bs = self;
//    [_backImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.and.right.equalTo(bs).with.offset(0);
//    }];
    _backImg.frame = self.frame;
    
    UIView *huise = [[UIView alloc] initWithFrame:_backImg.frame];
    huise.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    [self.backImg addSubview:huise];
    
    _imgBackLabel.frame = CGRectMake(9, 19, 62, 62);
    
    _clubImg.frame = CGRectMake(10, 20, 60, 60);
    
    _clubName.frame = CGRectMake(80, 30, self.frame.size.width - 80, 20);
    
//    CGFloat contentHeight = [[self class] heightWithText:_clubContent.text FontOfSize:13];
    _clubContent.frame = CGRectMake(80, 60, self.frame.size.width - 80, 40);
    [huise release];
}

////计算文本高
//+ (CGFloat)heightWithText:(NSString *)text FontOfSize:(CGFloat )fontOfSize
//{
//    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontOfSize]};
//    //最大范围
//    CGSize size = CGSizeMake(WIDTH - 100, 1000);
//    //计算 文本 需的rectangular
//    CGRect r = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//    //返回文本 的 高
//    return r.size.height;
//}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
